package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.pojo.*;
import com.dongdongshop.service.OrderItemService;
import com.dongdongshop.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @ClassName EcharsController
 * @Author RC
 * @date 2021.01.07 11:06
 */
@Controller
@RequestMapping("echars")
public class EcharsController {

    @Reference(timeout = 20000,check = false)
    private OrderService orderService;
    private static final Logger logger = LoggerFactory.getLogger(EcharsController.class);

    @RequestMapping("getChars")
    @ResponseBody
    public DataResult getChars (){
        try{
            logger.info("进入商品分类查询方法");
            Subject subject = SecurityUtils.getSubject();
            TbSeller seller = (TbSeller) subject.getPrincipal();
            Map<String,Object>  orderList  =orderService.getOrderAll(seller.getSellerId());

            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(orderList);
        }catch (Exception e){
            logger.info("查询失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }

    }
    @RequestMapping("getMonthlySales")
    @ResponseBody
    public DataResult getMonthlySales () {
        try {
            logger.info("进入商品分类查询方法");
            Subject subject = SecurityUtils.getSubject();
            TbSeller seller = (TbSeller) subject.getPrincipal();
            Map<String,Object> map = orderService.getMonthlySales(seller.getSellerId());

            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(map);
        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }

    }

}
